


  //const API_HEAD = `https://techcherry.cn/guoyuanapi/`;
  const API_HEAD = `https://techcherry.cn/guoyuanapi/`;

  var GetQueryString =(name)=>{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return unescape(r[2]); return 'null';
};

var decodeurl =(str)=>{
  var s = "";
  if (str.length == 0) return "";
  s = str.replace(/&amp;/g, "&");
  s = s.replace(/&lt;/g, "<");
  s = s.replace(/&gt;/g, ">");
  s = s.replace(/&nbsp;/g, " ");
  s = s.replace(/&#39;/g, "\'");
  s = s.replace(/&quot;/g, "\"");
  return s;  
}

function maskPhoneNumber(phoneNumber) {
  return phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}
var isBase64=(str)=>
 {
 return str.indexOf('data:image')>-1; 
}

//去重
var uniq=(array)=>{
  var temp = []; //一个新的临时数组
  array.forEach(x=>{
    if(temp.indexOf(Number(x) ) == -1)  temp.push(Number(x));
    console.log('uniq',temp);

  })
  
  return temp;
}


var 配置微信=(name)=>{
  获取微信数据( name, res => {
            let { nonceStr, ts, sign } = res;
            console.log({ nonceStr, ts, sign });

            sign = sign.toLowerCase();
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。

                appId: 'wx1cc77e0cd1a2bc3a', // 必填，公众号的唯一标识

                timestamp: ts, // 必填，生成签名的时间戳

                nonceStr: nonceStr, // 必填，生成签名的随机串

                signature: sign,// 必填，签名

                jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData'] // 必填，需要使用的JS接口列表

            });

        })

        wx.ready(function () {
            // 设置“分享给朋友”及“分享到QQ”的按钮点击后的分享内容
            wx.updateAppMessageShareData({
                title: '十五的月亮十三缘', // 分享标题
                desc: '参与拼图互动，赢国缘V3苏超联名小酒等好礼！', // 分享描述
                link: 'https://techcherry.cn/guoyuanh5/index.html', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: 'https://techcherry.cn/guoyuanh5/src/share_img.png', // 分享图标
                success: function () {
                   console.log('successupdateAppMessageShareData');
                    // 设置成功
                }
            });
            // 设置“分享到朋友圈”及“分享到QQ空间”的按钮点击后的分享内容
            wx.updateTimelineShareData({
               title: '十五的月亮十三缘', // 分享标题
                desc: '参与拼图互动，赢国缘V3苏超联名小酒等好礼！', // 分享描述
                link: 'https://techcherry.cn/guoyuanh5/index.html', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: 'https://techcherry.cn/guoyuanh5/src/share_img.png', // 分享图标
                success: function () {
                    // 设置成功
                    console.log('successupdateAppMessageShareData');
                }
            });
        });
}





var showAlert = (wrap,content,id,type)=>{
  
  wrap.append(` <div id="${id}" class="alert alert-${type}">
  <a href="#" class="close" data-dismiss="alert">&times;</a>
  <strong>提示！</strong>${content}  </div>`)
  $(`#${id}`).alert();
}

var getpay=(name)=>{
  let pay = 0;
  switch (name) {
    case '请选择': {
      pay = 0
      break;
  }
    case '牛仔拉链': {
        pay = 120
        break;
    }
    case '牛仔纽扣': {
        pay = 120
        break;
    }
    case '夏实训': {
        pay = 90
        break;
    }
    case '短T恤': {
        pay = 40
        break;
    }
    case '长T恤': {
        pay = 45
        break;
    }
    case '棒球服': {
        pay = 140
        break;
    }

    default:
        break;
}

return pay;

  
}

var checkPhone=(phone)=>{
  var re =/^[1][3,4,5,7,8][0-9]{9}$/;
  return re.test(phone)
}

function isIPhoneX(){
  
  
   if (screen.height == 812 && screen.width == 375){
       //是iphoneX 
       console.log('是iphoneX/XS 系列');
     return true;
     }else{
          //不是iphoneX
          return false; 
         } }


//默认GET方法
var fstHttps =(url,data,succ,type)=>{
  console.log(url,'fsturl');
  
    $.ajax({
            url,
            type:type?type:'POST',
             beforeSend:res=>{
              // res.setRequestHeader("token",'safjksdhfjksdbngjksdg' );
            },
            data,

            success: function (res) {
              succ&&succ(JSON.parse(res))
            },
            complete:res=>{
              console.log('complete',res.responseText);
            }
        })
}


var 卡片Https =(url,data,succ,type,fail,isasync)=>{
  let senddata = {},token=localStorage.getItem('token')
  if(token==null){
    //alert('token丢失')
    window.location.href='./index.html'
  }else{
    senddata['token'] = token
    senddata['userid'] = localStorage.getItem('userid')
    senddata['phone'] = localStorage.getItem('phone')
     for(var k in data){
       senddata[k] = data[k]
     }
    //  console.log(senddata,'senddata');
     
      $.ajax({
              url,
              type:type?type:'POST',
              data:senddata,
              async:isasync=='false'?!1:!0,
              // beforeSend:res=>{
              //   res.setRequestHeader("token","9fghahdbb3489fghbasjd" );
              // },
              success: function (res) {
                succ&&succ(JSON.parse(res))
              },
             
              complete: function (res) {
                console.log('complete--'+url,res);
                if(res.status!=200){
                  fail&&fail(JSON.parse(res.responseText))
                }
              },
          })
  }
}



var Https =(url,data,succ,type,fail,isasync)=>{
  let senddata = {},token=localStorage.getItem('token')
  if(token==null){
    //alert('token丢失')
    window.location.href='./index.html'
  }else{
    senddata['token'] = token
    senddata['userid'] = localStorage.getItem('userid')
    senddata['phone'] = localStorage.getItem('phone')
     for(var k in data){
       senddata[k] = data[k]
     }
    //  console.log(senddata,'senddata');
     
      $.ajax({
              url,
              type:type?type:'POST',
              data:senddata,
              async:isasync=='false'?!1:!0,
              // beforeSend:res=>{
              //   res.setRequestHeader("token","9fghahdbb3489fghbasjd" );
              // },
              success: function (res) {
                let result = JSON.parse(res)
                if(result.issuccess==-2){

                  localStorage.removeItem('token')
                  localStorage.removeItem('userid')
                  localStorage.removeItem('phone')
                  window.location.href='./index.html'
                }else{
                  succ&&succ(result)
                }
              },
             
              complete: function (res) {
                console.log('complete--'+url,res);
                if(res.status!=200){
                  fail&&fail(JSON.parse(res.responseText))
                }
              },
          })
  }
}

var excelHttps = (url, data, succ, type, fail, isasync) => {
  var senddata = { token: $.cookie('token') }
  if (!senddata.token) { window.location.href = './shopunknwo.html'; return }

  for (var k in data) {
    senddata[k] = data[k]
  }
  console.log(senddata, 'senddata');

  $.ajax({
    url,
    type: type ? type : 'POST',
    data: senddata,
    async: isasync == 'false' ? !1 : !0,
    // beforeSend:res=>{
    //   res.setRequestHeader("token",$.cookie('token') );
    // },
    success: function (res) {
      succ && succ(res)
    },

    complete: function (res) {
      if (res.status != 200) {
        fail && fail(JSON.parse(res.responseText))
      }
    },
  })
}

var formatDate = (date)=>{
 return `${date.getFullYear()}.${date.getMonth()+1}.${date.getDate()} ${date.getHours()>9?date.getHours():"0"+date.getHours()}:${date.getMinutes()>9?date.getMinutes():'0'+date.getMinutes()}`;
}

var formatDate1 = (sd)=>{
  return sd.getFullYear()+"-"+("0" + (sd.getMonth() + 1)).slice(-2)+"-"+("0" + sd.getDate()).slice(-2);
 }

// 家具


var 拉黑 = (ip,succ)=>{
  Https(`${API_HEAD}login/putinblack`
  ,{ip},res=>{
    succ&&succ(res)
  })
}

var getuser = (openid,succ)=>{
  Https(`${API_HEAD}users/getuser`
  ,{openid},res=>{
    succ&&succ(res)
  })
}

// var bind = (data,succ)=>{
//   Https(`${API_HEAD}student/bind`
//   ,data,res=>{
//     succ&&succ(res)
//   })
// }

var hasadd = (succ)=>{
  Https(`${API_HEAD}dinggou/hasadd`
  ,{openid:localStorage.getItem('openid')},res=>{
    succ&&succ(res)
  })
}

var info_findbyuserid = (id,succ)=>{
  Https(`${API_HEAD}dinggou/bk_findbyuserid`
  ,{id},res=>{
    succ&&succ(res)
  })
}


var addinfo = (data,succ)=>{
  Https(`${API_HEAD}dinggou/mp_add`
  ,data,res=>{
    succ&&succ(res)
  })
}

var canbuy = (openid,succ)=>{
  Https(`${API_HEAD}orders/canbuy`
  ,{openid},res=>{
    succ&&succ(res)
  })
}

var bind = (phone,succ)=>{
  fstHttps(`${API_HEAD}login/bind`
  ,{phone},res=>{
    succ&&succ(res)
  },'POST')
}


var uploadimg1 = (file, succ) => {

let token=localStorage.getItem('token')
  if(token==null){
    //alert('token丢失')
    window.location.href='./index.html'
  }else{
 var data = new FormData();
  data.append("token", token);
  data.append('file', file)
  data.append('userid', localStorage.getItem('userid'))
  data.append('phone', localStorage.getItem('phone'))
 $.ajax({
    url: `${API_HEAD}upload/h5_upload`, /*接口域名地址*/
    type: 'post',
    data,
    contentType: false,
    processData: false,
    success: res => {
      succ && succ(JSON.parse(res))
      console.log(res, 'resres')
    }
  })

  }



 
 
}





var uploadimg = (base64str,succ)=>{
  Https( `${API_HEAD}upload/upload`,{base64str} ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}

var 当前碎片 = (succ)=>{
  Https(`${API_HEAD}users/getmypiece`
  ,{},res=>{
    succ&&succ(res)
  },'POST')
}

var 新建one = (succ)=>{
  Https(`${API_HEAD}users/getpiece1`
  ,{},res=>{
    succ&&succ(res)
  },'POST')
}

var 更新碎片 = (type,succ)=>{
  Https(`${API_HEAD}users/getpiece${type}`
  ,{},res=>{
    succ&&succ(res)
  },'POST')
}
var 更新碎片4 = (imgurl,succ)=>{
  Https(`${API_HEAD}users/getpiece4`
  ,{imgurl},res=>{
    succ&&succ(res)
  },'POST')
}

var 开抽 = (succ)=>{
  Https(`${API_HEAD}lottery/chou`
  ,{},res=>{
    succ&&succ(res)
  },'POST')
}

var 填信息 = (data,succ)=>{
  Https(`${API_HEAD}lottery/write`
  ,data,res=>{
    succ&&succ(res)
  },'POST')
}

var 我的奖品 = (succ)=>{
  Https(`${API_HEAD}lottery/mygift`
  ,{},res=>{
    succ&&succ(res)
  },'POST')
}

var 获取微信数据 = (url,succ)=>{
  Https(`${API_HEAD}login/gettoken`
  ,{url},res=>{
    succ&&succ(res)
  },'POST')
}












  







